﻿using SqlSugar;
using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using GKQC.DbHelper.ViewModels;

namespace GKQC.DbHelper.DbModels
{
	//特性对比检测单单头
	[SugarTable("t_com_head")]
	public class ComHeadModel
	{
		public ComHeadModel()
		{
			this.Dtls = new List<ComDtlModel>();
			this.Standard = new StandardView();
			this.TestDate = DateTime.Now;
			this.CreateDate = DateTime.Now;
			this.Pn = string.Empty;
			this.LotNo = string.Empty;
			this.Remark = string.Empty;
			this.Eps = string.Empty;
			this.FoilN = string.Empty;
			this.FoilP = string.Empty;
			this.Humidity = string.Empty;
			this.LcMeter = string.Empty;
			this.LcrMeter = string.Empty;
			this.LeadWire = string.Empty;
			this.LotNo = string.Empty;
			this.Paste = string.Empty; 
			this.Rubber = string.Empty;
			this.Series = string.Empty;
			this.Size = string.Empty;
			this.Spec = string.Empty;
			this.Target = string.Empty;
			this.Temp = string.Empty;
		}

		/// <summary>
		/// 流水号
		/// </summary>		
		[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
		public long Id { get; set; }
		/// <summary>
		/// 批号
		/// </summary>		
		public string LotNo { get; set; }
		/// <summary>
		/// 料号
		/// </summary>		
		public string Pn { get; set; }
		/// <summary>
		/// 单据日期
		/// </summary>		
		public DateTime TestDate { get; set; }
		/// <summary>
		/// 系列
		/// </summary>		
		public string Series { get; set; }
		/// <summary>
		/// 规格
		/// </summary>		
		public string Spec { get; set; }
		/// <summary>
		/// 尺寸
		/// </summary>		
		public string Size { get; set; }
		/// <summary>
		/// 正箔
		/// </summary>		
		public string FoilP { get; set; }
		/// <summary>
		/// 负箔
		/// </summary>		
		public string FoilN { get; set; }
		/// <summary>
		/// 导针
		/// </summary>		
		public string LeadWire { get; set; }
		/// <summary>
		/// 电解纸
		/// </summary>		
		public string Eps { get; set; }
		/// <summary>
		/// 电解液
		/// </summary>		
		public string Paste { get; set; }
		/// <summary>
		/// 胶盖
		/// </summary>		
		public string Rubber { get; set; }
		/// <summary>
		/// 更新日期
		/// </summary>		
		public DateTime? ModiDate { get; set; }
		/// <summary>
		/// 建立日期
		/// </summary>		
		public DateTime CreateDate { get; set; }
		/// <summary>
		/// 报表ID
		/// </summary>		
		public int ReportId { get; set; }
		/// <summary>
		/// LCR仪器
		/// </summary>		
		public string LcrMeter { get; set; }
		/// <summary>
		/// LC仪器
		/// </summary>		
		public string LcMeter { get; set; }
		/// <summary>
		/// 电气检测数量
		/// </summary>		
		public int ElectricQty { get; set; }
		/// <summary>
		/// 尺寸检测数量
		/// </summary>		
		public int SizeQty { get; set; }
		/// <summary>
		/// 温度(℃)
		/// </summary>		
		public string Temp { get; set; }
		/// <summary>
		/// 湿度(%)
		/// </summary>		
		public string Humidity { get; set; }
		/// <summary>
		/// 检测人员
		/// </summary>		
		public string CreateUser { get; set; }
		/// <summary>
		/// 修改人
		/// </summary>		
		public string ModiUser { get; set; }
		/// <summary>
		/// 审核人
		/// </summary>		
		public string ApproveUser { get; set; }
		/// <summary>
		/// 审核日期
		/// </summary>		
		public DateTime? ApproveDate { get; set; }
		/// <summary>
		/// 目的
		/// </summary>		
		public string Target { get; set; }
		/// <summary>
		/// 備註
		/// </summary>		
		public string Remark { get; set; }

		[SugarColumn(IsIgnore = true)]
		public List<ComDtlModel> Dtls { get; set; }
		[SugarColumn(IsIgnore = true)]
		public StandardView Standard { get; set; }


		public double GetVoltage()
		{
			double voltage = 0;
			if (!string.IsNullOrWhiteSpace(this.Spec))
			{
				string[] ss = Spec.Split('/');
				if (ss.Length == 2)
				{
					double.TryParse(ss[1].Replace("V", string.Empty).Replace("v", string.Empty), out voltage);
				}
			}
			return voltage;
		}

		public double GetCap()
		{
			double cap = 0;
			if (!string.IsNullOrWhiteSpace(this.Spec))
			{
				string[] ss = Spec.Split('/');
				if (ss.Length == 2)
				{
					string s = ss[0].Replace("u", string.Empty).Replace("F", string.Empty).Replace("f", string.Empty)
						.Replace("p", string.Empty).Replace("n", string.Empty)
						.Replace("m", string.Empty).Replace("μ", string.Empty);
					double.TryParse(s, out cap);
				}
			}
			return cap;
		}
	}
}

